<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <input type="text" id="text" onkeyup="test(this)">
    <button onclick="test1()">点击</button>
    <script>
        var oText = document.getElementById('text');

        function test(obj) {
            var reg = /\s/;
            obj.value = obj.value.replace(reg, '')
        }
        console.log(3213);
        console.log(oText);
        // 身份证匹配
        // function test1() {
        //     var val = oText.value,
        //         reg = /^[1-9]\d{5}(18|19|20)\d{2}((0[1-9])|(1[0-2]))(([0-2][1-9])|[10|20|30|31])\d{3}[1-9Xx]$/,
        //         pass = reg.test(val);
        //     console.log(pass);
        // }
        // 至少六位，包含一个大写 一个小写 1个数字 1个特殊符号
        function test1() {
            var val = oText.value;
            var reg = /^.*(?=.{6,})(?=.*\d)(?=.*[A-Z])(?=.*[a-z])(?=.*[~!@#$%^&*?]).*$/;
            pass = reg.test(val);
            console.log(pass);
        }
        // 捕获分组
        var str = 'abcabc',
            reg = /(a)(b)(c)/;
        console.log(str.match(reg));
        // 非捕获分组
        reg = /(?:a)(b)(c)/;
        console.log(str.match(reg));

        //手机号
        var str = '15798071090',
            reg = /^(\(\+86\))?(13[0-9]|14[0-9]|15[012356789]|17[067]|18[0-9])\d{8}/;
        console.log(str.match(reg));
        // 日期
        var str = '1992.02.03',
            reg = /^(19|20)\d\d([-/.])(0[1-9]|1[0-2])\2(0[1-9]|[12][0-9]|3[01])/;
        console.log(str.match(reg));
        // 模板匹配
        var str = '{{titel}}dasdsad{{titel}}dasdsa{{content}}',
            reg = /{{(.*?)}}/g;
        console.log(str.match(reg));
        console.log(str.replace(reg, function($, $1) {
            console.log($, $1);
            return {
                titel: '梦幻',
                content: '内容'
            }[$1]
        }));
    </script>
</body>

</html>